package com.clj.view;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.clj.entity.StudentDO_clj;
import com.clj.handler.AddStudentViewHandler_clj;

/**
 * Author: Harry Chen
 * Date: 2023/02/24 15:52
 * Description: 主页面的各种组件
 */
public class AddStudentView_clj extends JDialog {
    JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10, 20));

    JLabel nameLabel = new JLabel("姓名：", JLabel.RIGHT);
    JTextField nameTxt = new JTextField();

    JLabel noLabel = new JLabel("学号：", JLabel.RIGHT);
    JTextField noTxt = new JTextField();

    JLabel homeLabel = new JLabel("住址：", JLabel.RIGHT);
    JTextField homeTxt = new JTextField();

    JLabel cnLabel = new JLabel("语文成绩：", JLabel.RIGHT);
    JTextField cnTxt = new JTextField();

    JLabel mathLabel = new JLabel("数学成绩：", JLabel.RIGHT);
    JTextField mathTxt = new JTextField();

    JLabel enLabel = new JLabel("英语成绩：", JLabel.RIGHT);
    JTextField enTxt = new JTextField();

    JButton addBtn = new JButton("添加");

    AddStudentViewHandler_clj addStudentViewHandlerClj;

    public AddStudentView_clj(MainView_clj mainViewClj) {
        super(mainViewClj, "添加学生", true);


        addStudentViewHandlerClj = new AddStudentViewHandler_clj(this, mainViewClj);
        nameLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(nameLabel);
        nameTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(nameTxt);

        noLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(noLabel);
        noTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(noTxt);

        homeLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(homeLabel);
        homeTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(homeTxt);

        cnLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(cnLabel);
        cnTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(cnTxt);

        mathLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(mathLabel);
        mathTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(mathTxt);

        enLabel.setPreferredSize(new Dimension(80, 30));
        jPanel.add(enLabel);
        enTxt.setPreferredSize(new Dimension(200, 30));
        jPanel.add(enTxt);

        addBtn.addActionListener(addStudentViewHandlerClj);
        jPanel.add(addBtn);
        Container contentPane = getContentPane();
        contentPane.add(jPanel);


        setSize(350, 500);
        setLocationRelativeTo(null);
        //DISPOSE_ON_CLOSE只销毁当前窗体
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);
    }

    public StudentDO_clj buildStudentDO() {
        StudentDO_clj studentDOClj = new StudentDO_clj();
        studentDOClj.set姓名(nameTxt.getText());
        studentDOClj.set学号(noTxt.getText());
        studentDOClj.set住址(homeTxt.getText());
        studentDOClj.set语文(Double.valueOf(cnTxt.getText()));
        studentDOClj.set数学(Double.valueOf(mathTxt.getText()));
        studentDOClj.set英语(Double.valueOf(enTxt.getText()));
        return studentDOClj;
    }
}
